﻿using Microsoft.Practices.Unity;
using Emico.Data.Repository;

namespace Emico.Data.Entity.Tests.Repository
{
	public static partial class TestContextConfig
	{
		public static void Register(IUnityContainer container)
		{
			RegisterUnitOfWork(container);
			RegisterRepository(container);
		}

		private static void RegisterUnitOfWork(IUnityContainer container)
        {
            container.RegisterType<ITestContextUnitOfWork>(new InjectionFactory(c => {
                var context = new Imples.TestContextUnitOfWork(
                        new TestContext()
                    );
                context.SetRepositoryResolver((t, w) => (IRepository)c.Resolve(t, new ParameterOverride("wrapper", w)));
                return context;
            }));
		}

		private static void RegisterRepository(IUnityContainer container)
        {                
			container.RegisterType<IBaseRepository, Imples.BaseRepository>(new TransientLifetimeManager());
			container.RegisterType<IDerivedARepository, Imples.DerivedARepository>(new TransientLifetimeManager());
			container.RegisterType<IDerivedBRepository, Imples.DerivedBRepository>(new TransientLifetimeManager());
			container.RegisterType<ISimpleRepository, Imples.SimpleRepository>(new TransientLifetimeManager());
        }	
	}
}



